#!/bin/sh
# This regression test is a part of SIPp.
# A final response to an INVITE transaction that comes again before its
# <send ack_txn> goes out used to abort SIPp on an assertion. A copy of
# the 200 must be absorbed, and a forked 200 (another To-tag) handled as
# an unexpected message. -nr keeps the UDP retransmission detection from
# absorbing the copy first, as a message received in between would.
. "`dirname "$0"`/../functions"; init

sippbg -sf uas.xml -key tag2 01 -nr -i 127.0.0.1 -p 25100 -m 1
sippfg -sf uac.xml -nr -i 127.0.0.1 -p 25101 -m 1 127.0.0.1:25100 \
    -timeout 5 -timeout_error >/dev/null 2>&1
copy=$?

sippbg -sf uas.xml -key tag2 02 -nr -i 127.0.0.1 -p 25102 -m 1
sippfg -sf uac.xml -nr -i 127.0.0.1 -p 25103 -m 1 127.0.0.1:25102 \
    -timeout 5 -timeout_error >/dev/null 2>&1
fork=$?

if test $copy -ne 0; then
    fail "UAC failed with $copy on a copy of the 200"
elif test $fork -ne 1; then
    fail "UAC ended with $fork on a forked 200, not 1"
else
    ok
fi
